package digui;

public class offer55 {

    int maxDeep=0;
    public int maxDepth(TreeNode root) {
        dfs(root,1);
        return  maxDeep;
    }

    public void  dfs(TreeNode root,int t){
        if (root==null){
            return;
        }
        if (t>maxDeep){
            maxDeep=t;
        }
        dfs(root.left,t+1);
        dfs(root.right,t+1);

    }

    public static void main(String[] args) {
        TreeNode root= new TreeNode(5);
        TreeNode treeNode1 = new TreeNode(3);
        TreeNode treeNode2= new TreeNode(1);
        TreeNode treeNode3 = new TreeNode(2);
        TreeNode treeNode4= new TreeNode(6);
        root.left=treeNode1;
        root.right=treeNode3;
        treeNode1.left=treeNode2;
        treeNode3.right=treeNode4;
        offer55 offer55 = new offer55();
        System.out.println(offer55.maxDepth(root));

    }


}
